package com.github.shiqiyue.app.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.shiqiyue.app.modules.sys.entity.RolePermission;
import com.github.shiqiyue.app.modules.sys.mapper.RolePermissionMapper;

import com.github.shiqiyue.app.modules.sys.service.IRolePermissionService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色-权限 服务实现类
 * </p>
 *
 * @author wenyao.wu
 * @since 2018-10-16
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {

    @Override
    public boolean deleteByRoleId(Long roleId) {
        return this.remove(new UpdateWrapper<RolePermission>().eq(RolePermission.ROLE_ID, roleId));
    }

    @Override
    public List<RolePermission> findByRoleId(Long roleId) {
        return baseMapper.findByRoleId(roleId);
    }

    @Override
    public boolean updateByRoleId(Long roleId, List<RolePermission> rolePermissions) {
        this.deleteByRoleId(roleId);
        if (CollectionUtils.isNotEmpty(rolePermissions)) {
            this.saveBatch(rolePermissions);
        }
        return true;
    }
}
